<?php

/**
 * Description de la classe Colonne
 */
class Column {

    private $id;
    private $project_id;
    private $column_name;
    private $column_usual_name;
    private $order;

    /**
     *
     * @param type $id
     * @param type $project_id
     * @param type $column_name
     * @param type $column_usual_name
     * @param type $order
     */
    public function __construct($id, $project_id, $column_name, $column_usual_name, $order) {
        $this->id = $id;
        $this->project_id = $project_id;
        $this->column_name = $column_name;
        $this->column_usual_name = $column_usual_name;
        $this->order = $order;
    }

    /**
     * Getter Column id
     * @return type int
     */
    public function getId() {
        return $this->id;
    }

    /**
     * Getter Project id
     * @return type string
     */
    public function getProjectId() {
        return $this->project_id;
    }

    /**
     * Getter Column name
     * @return type int
     */
    public function getColumnName() {
        return $this->column_name;
    }

    /**
     * Getter Column usual name
     * @return type int
     */
    public function getColumnUsualName() {
        return $this->column_usual_name;
    }

    /**
     * Getter Column order
     * @return type int
     */
    public function getOrder() {
        return $this->order;
    }

    /**
     * Sauvegarde les colonnes d'un projet
     */
    public function save() {
        Sql::exec("INSERT INTO wsk_columns (id_project, column_name, column_usual_name, order) VALUES ('" . $this->project_id . "', '" . $this->column_name . "', '" . $this->column_usual_name . "', '" . $this->order. "')");
    }

    /**
     * Mets à jour les colonnes du projet
     */
    public function update() {
        Sql::exec("UPDATE wsk_columns SET column_name = '" . $this->column_name . "', column_usual_name='" . $this->column_usual_name . "', order='" . $this->order . "', date_updated='" . $this->graphe_type . " where _id = '" . $this->id . "'");
    }

    /**
     * Supprime une colonne d'un projet
     */
    public function delete() {
        Sql::exec("DELETE FROM wsk_columns WHERE _id = $this->id");
    }

    /**
     * Retourne une liste avec toutes les colonnes
     * @return List of Columns
     */
    public static function getColumns() {

        $list = Array();

        $req = mysql_query("SELECT * FROM wsk_columns");
        while ($row = mysql_fetch_array($req)) {
            $list[] = new Column($row["id_column"], $row["id_project"], $row["column_name"], $row["column_usual_name"], $row["order"]);
        }

        mysql_free_result($req);

        return $list;
    }
    
/**
     * Retourne une liste de toutes les colonnes d'un projet
     * @return List of Columns of project
     */
    public static function getColumnsProject($id_project) {

        $list = Array();

        $req = mysql_query("SELECT * FROM wsk_columns WHERE id_project='" . $id_project . "' AND date_deleted IS NULL");
        while ($row = mysql_fetch_array($req)) {
            $list[] = new Column($row["id_column"], $row["id_project"], $row["column_name"], $row["column_usual_name"], $row["order"]);
        }

        mysql_free_result($req);

        return $list;
    }
}

?>